package service

import (
	"openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/job_workflow/dao"
	"openeuler.org/PilotGo/PilotGo-plugin-automation/internal/module/job_workflow/model"
	"openeuler.org/PilotGo/PilotGo-plugin-automation/pkg/response"
)

func CreateWorkflow(data *model.TaskWorkflowDTO) error {
	if err := dao.CreateWorkflow(data); err != nil {
		return err
	}
	return nil
}

func DeleteWorkflow(id []int) error {
	if err := dao.DeleteWorkflow(id); err != nil {
		return err
	}
	return nil
}

func UpdateWorkflow(data *model.TaskWorkflowDTO) error {
	if err := dao.UpdateWorkflow(data); err != nil {
		return err
	}
	return nil
}

func QueryWorkflow(query *response.PagedQuery, publishStatus, tag string) ([]model.TaskWorkflow, int, error) {
	workflows, total, err := dao.QueryWorkflows(query, publishStatus, tag)
	if err != nil {
		return nil, 0, err
	}
	return workflows, total, nil
}

func GetWorkflows() ([]model.TaskWorkflow, error) {
	workflows, err := dao.GetWorkflows()
	if err != nil {
		return nil, err
	}
	return workflows, nil
}

func GetWorkflowById(id string) (interface{}, error) {
	info, err := dao.GetWorkflowById(id)
	if err != nil {
		return nil, err
	}
	return info, nil
}

func PublishWorkflow(id int, newStatus string) error {
	return dao.PublishWorkflow(id, newStatus)
}

func RelatedTaskWorkflowToSync(workflowId string) error {
	return dao.RelatedTaskWorkflowToSync(workflowId)
}
